package com.example.ele_guarantee_hh_pro.comclass;
import com.cloudcc.deveditor.core.CCObject;
import com.cloudcc.deveditor.core.CCService;
import com.cloudcc.deveditor.core.ServiceResult;
import com.cloudcc.deveditor.core.UserInfo;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import java.util.List;
public class EleoppTest {

    private static CCService cs;

    private UserInfo userInfo;

    public EleoppTest(UserInfo userInfo) throws Exception {
        cs = new CCService(userInfo);
        this.userInfo = userInfo;
    }


    /*更新公招信息中的投标频次*/
    public void updateEleopp(String data) {
        JSONObject dataInfo = JSONObject.fromObject(data);
        String id = dataInfo.get("id") == null ? "" : dataInfo.get("id") + "";
        String tbpc = dataInfo.get("tbpc") == null ? "" : dataInfo.get("tbpc") + "";
        String update = "update ele_num set frequece ='" + tbpc + "' where id ='" + id + "' ";
        cs.cqlQuery("ele_num", update);
    }
    //    公招信息中的客户投标频率
    public String findEleNum() {
        String findEleNum = "select a.frequece frequece ,d.name  name ,a.fk_psmc fkPsmc,a.id from ele_num  a " +
                "inner join ghjl b  on a.fk_psmc  = b.jyzx  and b.is_deleted='0' " +
                "inner join ccuser c on c.id = b.yh  and c.id ='" + userInfo.getUserId() + "' and c.is_deleted='0' " +
                "inner join psmc d on  d.id = a.fk_psmc and d.is_deleted='0' ";
        List<CCObject> ccObjects = cs.cqlQuery("", findEleNum);
        JSONArray dataInfoList = new JSONArray();
        if (ccObjects.size() > 0) {
            for (CCObject cc : ccObjects) {
                JSONObject dataInfo = new JSONObject();
                String fkpsmc = cc.get("fkpsmc") == null ? "" : cc.get("fkpsmc") + "";
                String name = cc.get("name") == null ? "" : cc.get("name") + "";
                String frequece = cc.get("frequece") == null ? "" : cc.get("frequece") + "";
                String id = cc.get("id") == null ? "" : cc.get("id") + "";
                dataInfo.put("frequece", frequece);
                JSONObject jyzxInfo = new JSONObject();
                jyzxInfo.put("label", name);
                jyzxInfo.put("value", fkpsmc);
                dataInfo.put("id", id);
                dataInfo.put("fkpsmc", jyzxInfo);
                dataInfoList.add(dataInfo);
            }
        }
        return String.valueOf(dataInfoList);
    }
}
